/**
 *  home.js v1.0 -新版本工作台 js文件
 *	author Huahua
 *
 */
var userid = "";
var username = "";
var userorg = "";
var userpos = "";
var today = new Date();
//var thisday = formatdate(today).substring(5,10);
//var thisday = "10-08";
/**
 * 1.获取用户信息
 * @returns {String}
 */
function getUserInfo() {
	$.ajax({
		type : 'GET',
		dataType:"json",
        cache:false,
        async:false,
		url : "/palace/root.getUserInfo.do",
		error : function() {
			alertFunc('获取用户信息失败！');

		},
		success : function(res) {
			if (res.status == "OK") {
				loadUserInfo(res);
				if(res.data.resetpwd){
//					changePwd();
					firstChangePwd(); 	//初次修改密码					
				}
				/*if(thisday == (res.data.birthday).substring(5,10)){
					loadBirthWish();	
				}*/
			}else if (res.status == "Failed") {
				loadUserInfoError(res);
			}
		}
	});
}

/**
 * 2.加载用户信息
 * @param res
 */

function loadUserInfo(res) {
	$("#userinfo").html(
				'<i id="useri"><a href="#" onclick="javascript:displayModifyInfoDialog()" style="cursor:hand" title="修改个人信息">'+res.data.username+'</a></i>'+
				'<i>'+res.data.orgname+'</i>'+
				'<i class="position">'+res.data.position+'</i>');
	//$("#userinfo").html('<i id="useri"><a href="#" onclick="javascript:displayModifyInfoDialog()" style="cursor:hand" title="修改个人信息">'+res.data.username+'</a></i>');
	
	userid = res.data.userid;
	username = res.data.username;
	userorg = res.data.orgname;			//兼职身份登录的人的部门
	userpos = res.data.actualposition;	//兼职身份登录的人的现工作岗位
}
//加载生日祝福
/*function loadBirthWish(){
	showBirth();
	var typewriter=document.querySelector(".typewriter"),
    	code=typewriter.innerHTML,
    	pos=0,
    	len=code.length;
	typewriter.innerHTML="";
	typewriter.style.display="block";
	function typewriting(){
	pos++;
	if(pos<=len)
	{
	    switch(code.charAt(pos))
	    {
	        case "<":
	            pos=code.indexOf(">",pos);
	            break;
	        case "&":
	            pos=code.indexOf(";",pos);
	            break;
	    }
	    typewriter.innerHTML=code.substring(0,pos);
	    setTimeout(typewriting,100);
	}
	else
	{
	    typewriter.classList.add("gameover");
	}
	}
	typewriting();
	setTimeout("hideBirth()",5000);	//设置有效时间5秒
}

function showBirth(){
	$('.birthmain').show();
}
function hideBirth(){
	$('.birthmain').hide();
}*/


/**
 * 3.加载错误信息
 * @param res
 */
function loadUserInfoError(res) {
	$("#userinfo").html(res.error);
}



/**
 * 16.退出
 */
function logout() {
	clearCookie();
	$.ajax({
		type : 'GET',
		dataType:"json",
        cache:false,
        async:false,
		url : "loginservlet.logout.do",
		success : function(res) {
			if(res.status == "OK"){
				window.top.location.href=projectroot+"entry.html";
			}
		}
	});
//	window.top.location.href=projectroot+"entry.html";
}

function clearCookie() {
	var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
	if (keys) {
		for (var i = keys.length; i--;)
			document.cookie = keys[i] + '=0;expires='
					+ new Date(0).toUTCString()
	}
}

function timestamp(url) {
	var getTimestamp = new Date().getTime();
	if (url.indexOf("?") > -1) {
		url = url + "&_=" + getTimestamp
	} else {
		url = url + "?_=" + getTimestamp
	}
	return url;
}



















